package com.wewins.fota.bean.bo.excel;

import com.wewins.fota.bean.bo.excel.column.ExcelColumn;
import com.wewins.fota.bean.bo.excel.column.ExcelColumnGroup;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.stream.Stream;

public interface DataSource {
    default RowData convertColumnData() {
        ArrayList<Column> columns = new ArrayList<>();
        Class<? extends DataSource> clazz = this.getClass();
        Field[] fields = clazz.getDeclaredFields();
        Stream.of(fields).forEach(item -> {
            try {
                ExcelColumn column = item.getAnnotation(ExcelColumn.class);
                Class<? extends Column> cellClazz = column.cellClazz();
                Column instance = cellClazz.newInstance();
                item.setAccessible(true);
                instance.setValue(item.get(this));
                columns.add(instance);
            } catch (Exception e) {
                e.printStackTrace();
            }
        });
        return RowData.builder().columns(columns).build();
    }
}
